package com.autotest.sync;

import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Toolkit;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import com.autotest.sync.android.Sync;

/**
 * 主操作窗口
 * @author zy
 *
 */
public class MainFrame {

	private JFrame frame;
	private TopPanel topPanel;
	private BottomPanel bottomPanel;
	
	/**
	 * Create the application.
	 */
	public MainFrame() {
		initialize();
		initListener();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setTitle("多终端手势操作同步工具");
		frame.setSize(500, 400);
		frame.setResizable(false);
		Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
		frame.setLocation(dim.width / 2 - 250, dim.height / 2 - 200);
		frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		frame.getContentPane().setLayout(new BorderLayout(0, 0));
		
		topPanel = new TopPanel();
		frame.getContentPane().add(topPanel, BorderLayout.NORTH);
		
		bottomPanel = new BottomPanel();
		frame.getContentPane().add(bottomPanel, BorderLayout.CENTER);
		topPanel.register(bottomPanel);
	}
	
	// 初始化监听
	private void initListener() {
		frame.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				String msg = "确定关闭吗？";
				int option = JOptionPane.showConfirmDialog(null, msg,
						"温馨提示", JOptionPane.YES_NO_OPTION);
				if (option == JOptionPane.YES_OPTION) {
					Sync.getInstance().exit();
					System.exit(0);
				}
			}
		});
	}

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					JFrame.setDefaultLookAndFeelDecorated(true);
					JDialog.setDefaultLookAndFeelDecorated(true);
					MainFrame window = new MainFrame();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
}
